<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
	$userid= $_SESSION['iduser'];
	include '../connection/connection.php';	
	include '../value/value_kr.php';
	$sql = mysql_query("select a.carnumber,a.camera_id,co.id,co.name,co.host,co.go_mode,a.filename,d.cartype,d.code1,co.pos_x,co.pos_y 
			from alarm_display a,favourite f,configcamera co,alarm_dat d 
			where a.carnumber=d.carnumber and co.id=f.camera_ID and co.id=a.camera_id GROUP BY a.carnumber",$connection);
	?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
	* {font-family:Arial, Helvetica, sans-serif; font-size:13px; list-style:none; margin:0; padding:0}
	body { background:white}
	.clear {clear:both}
	#popup {width:600px; padding:20px; background:#618091}
	.ptop {background:#EFF3FA; border:1px solid #828282; overflow:scroll; padding:20px; height:200px}
	.plist li {border-bottom:1px dotted #999; padding:10px 0}
	.plist li p {float:right; width:400px}
	.phinh { padding:10px}
	.phinh img {width:580px}
	.pfoot { padding:10px}
	.inbtn { background:url(../images/bgbtn.png) repeat-x; border:1px solid #035a97; height:28px;
	 width:100px; font-size:15px; color:white; cursor:pointer; border-radius: 6px}
	 .inbtnDisable { background:#1E7BBD repeat-x; border:1px solid #035a97; height:28px; width:100px; font-size:15px;
	  color:white; cursor:default; border-radius: 6px;opacity: .5;}
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
	function processCheck(tenid,field){
		if(document.getElementById(tenid).checked == true){
			for(var i = 0;i<field.length;i++){}
			document.getElementById(tenid).checked = true;
			var carnumber = document.getElementById(tenid).value;
			document.getElementById('nameinsert').setAttribute("class","inbtn");
			document.getElementById('nameinsert').className = "inbtn";
			document.getElementById('nameinsert').disabled = false;
			$.ajax({url:"load_image_popup_carcrime.php?carnumber="+carnumber,success:function(result){
				document.getElementById('loadimage').innerHTML=result;
				}
			});
		}else if(document.getElementById(tenid).checked == false){
			document.getElementById('nameinsert').setAttribute("class","inbtnDisable");
			document.getElementById('nameinsert').className = "inbtnDisable";
			document.getElementById('nameinsert').disabled = true;
		}
	}
	function insertComment(field){alert('dd');
			 var txtcomment = document.getElementById("txtcomment").value;
			 var userid = '<?=$_SESSION['iduser']?>';
			for(var i = 0;i<field.length;i++){
				if(field[i].type == 'checkbox' && field[i].checked){
					var a = field[i].value;
					alert('carnumber = ' + a);
					$.ajax({url:"insert_comment_popup_carcrime.php?carnumber="+a+"&comment="+txtcomment,success:function(result){
						 $.ajax({url:"check_exist_carcrime.php",success:function(result){
						  			if(result=='no'){
						  	   			alert('have not carcrime');
						  	   			return false;
						  	   		}else{
						  	   			newwindow=window.open('popup_carcrime.php','name','height=800,width=800');
						  	    		if (window.focus) {newwindow.focus();}
						  	   		}
						  			}
						  		});
				      }
			      });
				}
			}
	}
</script>
</head>
<body>
<div id="popup">
<form action="#" id="formCheck" name="formCheck">
	<div class="ptop">
    	<ul class="plist">
    	<?php $i=0;
	  while ($row = mysql_fetch_array($sql)){ $i++;
	  	$datetime = explode("_",$row[filename]);
	  	$tempdate = strtotime($datetime[0]);
	  	$y = date("Y",$tempdate);
	  	$d = substr($datetime[0], -2);
	  	$ymd = date("Ymd",$tempdate);
	  	$temphour = strtotime($datetime[1]);
	  	$h = date("H",$temphour);
	  	$m = date("i",$temphour);
	  	$s = date("s",$temphour);
	  	$imga = "http://".$row[host]."/".$y."/".$ymd."/".$h."/".$m."/".$row[filename];
	  	?>
        	<li>
            	<input type="checkbox"  name="checkcarcrime"
            	id="<?php echo 'checkcarcr'.$i?>" onclick="processCheck(this.id,document.formCheck.checkcarcrime);"
            	value="<?=$row[carnumber];?>"/> <?=$row[carnumber];?>
                <p><?=$row[name]."--";?><?php if ($row[go_mode]==0){echo $l_go;}else {echo $l_come;}?>
  					<?="--".$row[cartype]."--".$y."-".$d."    ".$h."-".$m."-".$s?></p>
  					<img alt="" src="<?=$imga?>" style="display: none;" id="imgs" name="imgs">
  					<input type="hidden" name="carnumber" id="carnumber" value="<?=$row[carnumber]?>">
  					<?php $_SESSION['cameraid'] = $row['camera_id'];?>
                <div class="clear"></div>
            </li>
              <?php }?>
        </ul>
    </div>
	<div class="phinh" id="loadimage"><img src="<?=$imga?>" alt="" /></div>
	    <div class="pfoot">
	    	<input type="text" class="intext" style="width:450px; height:50px; vertical-align:middle" id="txtcomment" name="txtcomment"/>
	     	<input type="button" class="inbtnDisable" value="insert" style="vertical-align:middle" 
	     	onclick="insertComment(document.formCheck.checkcarcrime);" name="nameinsert" id="nameinsert" disabled="disabled"/> 
	</div>
 </form>    
</div>
</body>
</html>
<?php mysql_close($connection);?>
